<html>
 <head>
  <link href="./leetcode-problem.css" rel="stylesheet" type="text/css">
 </head>
 <body>
  <div class="question_difficulty">
   难度：Hard
  </div>
  <div>
   <h1 class="question_title">
    1034. Subarrays with K Different Integers
   </h1>
   <p>
    Given an array
    <code>
     A
    </code>
    of positive integers, call a (contiguous, not necessarily distinct) subarray of
    <code>
     A
    </code>
    <em>
     good
    </em>
    if the number of different integers in that subarray is exactly
    <code>
     K
    </code>
    .
   </p>
   <p>
    (For example,
    <code>
     [1,2,3,1,2]
    </code>
    has
    <code>
     3
    </code>
    different integers:
    <code>
     1
    </code>
    ,
    <code>
     2
    </code>
    , and
    <code>
     3
    </code>
    .)
   </p>
   <p>
    Return the number of good subarrays of
    <code>
     A
    </code>
    .
   </p>
   <p>
    &nbsp;
   </p>
   <p>
    <strong>
     Example 1:
    </strong>
   </p>
   <pre>
<strong>Input: </strong>A = <span id="example-input-1-1">[1,2,1,2,3]</span>, K = <span id="example-input-1-2">2</span>
<strong>Output: </strong><span id="example-output-1">7</span>
<strong>Explanation: </strong>Subarrays formed with exactly 2 different integers: [1,2], [2,1], [1,2], [2,3], [1,2,1], [2,1,2], [1,2,1,2].
</pre>
   <p>
    <strong>
     Example 2:
    </strong>
   </p>
   <pre>
<strong>Input: </strong>A = <span id="example-input-2-1">[1,2,1,3,4]</span>, K = <span id="example-input-2-2">3</span>
<strong>Output: </strong><span id="example-output-2">3</span>
<strong>Explanation: </strong>Subarrays formed with exactly 3 different integers: [1,2,1,3], [2,1,3], [1,3,4].
</pre>
   <p>
    &nbsp;
   </p>
   <p>
    <strong>
     Note:
    </strong>
   </p>
   <ol>
    <li>
     <code>
      1 &lt;= A.length &lt;= 20000
     </code>
    </li>
    <li>
     <code>
      1 &lt;= A[i] &lt;= A.length
     </code>
    </li>
    <li>
     <code>
      1 &lt;= K &lt;= A.length
     </code>
    </li>
   </ol>
  </div>
  <div>
   <h1 class="question_title">
    1034. K 个不同整数的子数组
   </h1>
   <p>
    给定一个正整数数组
    <code>
     A
    </code>
    ，如果
    <code>
     A
    </code>
    &nbsp;的某个子数组中不同整数的个数恰好为
    <code>
     K
    </code>
    ，则称
    <code>
     A
    </code>
    的这个连续、不一定独立的子数组为
    <em>
     好子数组
    </em>
    。
   </p>
   <p>
    （例如，
    <code>
     [1,2,3,1,2]
    </code>
    中有&nbsp;
    <code>
     3
    </code>
    &nbsp;个不同的整数：
    <code>
     1
    </code>
    ，
    <code>
     2
    </code>
    ，以及&nbsp;
    <code>
     3
    </code>
    。）
   </p>
   <p>
    返回&nbsp;
    <code>
     A
    </code>
    &nbsp;中
    <em>
     好子数组
    </em>
    的数目。
   </p>
   <p>
    &nbsp;
   </p>
   <p>
    <strong>
     示例 1：
    </strong>
   </p>
   <pre><strong>输出：</strong>A = [1,2,1,2,3], K = 2
<strong>输入：</strong>7
<strong>解释：</strong>恰好由 2 个不同整数组成的子数组：[1,2], [2,1], [1,2], [2,3], [1,2,1], [2,1,2], [1,2,1,2].
</pre>
   <p>
    <strong>
     示例 2：
    </strong>
   </p>
   <pre><strong>输入：</strong>A = [1,2,1,3,4], K = 3
<strong>输出：</strong>3
<strong>解释：</strong>恰好由 3 个不同整数组成的子数组：[1,2,1,3], [2,1,3], [1,3,4].
</pre>
   <p>
    &nbsp;
   </p>
   <p>
    <strong>
     提示：
    </strong>
   </p>
   <ol>
    <li>
     <code>
      1 &lt;= A.length &lt;= 20000
     </code>
    </li>
    <li>
     <code>
      1 &lt;= A[i] &lt;= A.length
     </code>
    </li>
    <li>
     <code>
      1 &lt;= K &lt;= A.length
     </code>
    </li>
   </ol>
  </div>
 </body>
</html>